package com.scaupos.mis11c.Controller;

import com.scaupos.mis11c.Entities.Clothes;
import com.scaupos.mis11c.Repository.ClothesRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*
* 若将前后端项目整合，请将api路径修改为/api/xxx
* 否则不需要更改路径
* */

@RestController
public class ClothesController {
    @Autowired
    ClothesRepository clothesRepository;


    @RequestMapping("/orders")
    public Clothes findClothes(@RequestParam(value="barcode")String barcode){
        return clothesRepository.findByBarcode(barcode);
    }


    @PostMapping("/addclothes")
    @ResponseBody
    public Clothes addClothes(@RequestBody Clothes clothes){
        clothesRepository.save(clothes);
        return clothes;
    }

    @RequestMapping("/allclothes")
    @ResponseBody
    public List<Clothes> allclothes(){
        return clothesRepository.findAll();
    }

}
